<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title><spring:message code="template.manage"/></title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {

		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
        function cheackAll(obj){
            var isCheck = $(obj).is(":checked");

            $("#contentTable").find("input[type='checkbox']").each(function(){
                $(this).prop("checked", isCheck);
            });
        }
        function batchProcesst(flag){
            var msg = "";
            var title="";
            var len=$("#contentTable input[type='checkbox']:checked").length;
            if(len <=0){
                alertx("<spring:message code='tips.mustcheck' />")

            }else {
                if (flag == 'pass') {
                    msg = "<spring:message code='tips.allpass' />"

                    confirmx(msg, function () {
                        var templetList = "";
                        var txt= $.trim($("#txt").val());
                        var comment ="";
                        $("#contentTable").find("input[type='checkbox']").each(function () {
                            if ($(this).prop('checked')) {
                                var egId = $(this).attr("id");
                                templetList = templetList + "'" + egId + "',";
                            }
                        });
                        $.ajax({
                            type: "POST",
                            url: "${ctx}/templet/eleTemplet/checkList",
                            data: {templetList: templetList, flag: flag, type: 'approval',comment:comment},
                            datatype: "json",
                            success: function (data) {
                                alertx(data.msg, function () {
                                    window.location.reload();
                                });
                            },
                            error: function () {
                                alertx("<spring:message code='tips.contactadmin' />");
                                console.log(e);
                            }
                        });
                    });
                }
                else if (flag == 'reject') {
                    title = "<spring:message code='tips.checkcomment' />";
                    msg = "<spring:message code='tips.checkcomment1' />";
                    promptx(title,msg, function(v){
                        var templetList = "";
                        var txt= $.trim(v);
                        var comment =txt;
                        $("#contentTable").find("input[type='checkbox']").each(function () {
                            if ($(this).prop('checked')) {
                                var egId = $(this).attr("id");
                                templetList = templetList + "'" + egId + "',";
                            }
                        });
                        $.ajax({
                            type: "POST",
                            url: "${ctx}/templet/eleTemplet/checkList",
                            data: {templetList: templetList, flag: flag, type: 'approval',comment:comment},
                            datatype: "json",
                            success: function (data) {
                                alertx(data.msg, function () {
                                    window.location.reload();
                                });
                            },
                            error: function () {
                                alertx("<spring:message code='tips.contactadmin' />");
                                console.log(e);
                            }
                        });
                    });
                }

            else{ msg = "<spring:message code='tips.delall' />"
                    confirmx(msg, function(){
                        var templetList = "";
                        var comment ="";
                        $("#contentTable").find("input[type='checkbox']").each(function () {
                            if ($(this).prop('checked')) {
                                var egId = $(this).attr("id");
                                templetList = templetList + "'" + egId + "',";
                            }
                        });
                        $.ajax({
                            type: "POST",
                            url: "${ctx}/templet/eleTemplet/checkList",
                            data: {templetList: templetList, flag: flag, type: 'approval',comment:comment},
                            datatype: "json",
                            success: function (data) {
                                alertx(data.msg, function () {
                                    window.location.reload();
                                });
                            },
                            error: function () {
                                alertx("<spring:message code='tips.contactadmin' />");
                                console.log(e);
                            }
                        });
                    });
                }


        }
        }
    	function resubmit(){
			var groupList = "";
            var txt= $.trim($("#txt").val());
            var comment =txt;
            $("#contentTable").find("input[type='checkbox']").each(function () {
                if ($(this).prop('checked')) {
                    var egId = $(this).attr("id");
                    groupList = groupList + "'" + egId + "',";
                }
            });
            $.ajax({
                type: "POST",
                url: "${ctx}/templet/eleTemplet/resubmit",
                data: {templetList: groupList,comment:comment},
                datatype: "json",
                success: function (data) {
                    alertx(data.msg, function () {
                        window.location.reload();
                    });
                },
                error: function (e) {
                    alertx("<spring:message code='tips.contactadmin' />");
                    console.log(e);
                }
            });
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/templet/eleTemplet/mylist?flag=false"><spring:message code="menu.Approval.Approval_ecord.Interface_Approval"/></a></li>
	</ul>
    <div class="control-group" style="margin-bottom:20px;/*background-color:#f5f5f5;*/" >
            <input type="button" value="<spring:message code='Batch.pass'/>" class="btn btn-default btn-lg" onclick="batchProcesst('pass');">
            <input type="button" value="<spring:message code='Batch.rejection'/>" class="btn btn-default btn-lg" onclick="batchProcesst('reject');">
            <input type="button" value="<spring:message code='Batch.deletion'/>" class="btn btn-default btn-lg" onclick="batchProcesst('delete');">
        <form:form id="searchForm" modelAttribute="eleTempletPublish" action="${ctx}/templet/eleTemplet/mychecklist" method="post"
                   class="breadcrumb form-search" style="float:right;padding-bottom:0px;padding-top:0px;">
            <input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
            <input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
            <input name="flag" type="hidden" value="${flag}"/>
           		<input name="isFirst" type="hidden" value="${isFirst}"/>
           
            <ul class="ul-form">
               <%-- <li><label><spring:message code="template.name"/>：</label>
                    <form:input path="name" htmlEscape="false" maxlength="255" class="input-medium"/>
                </li>--%>
                <li><label><spring:message code='common.status'/>：</label>
                    <form:select path="delFlag" htmlEscape="false"  class="input-medium">
                        <form:option value="5"><spring:message code="all"/></form:option>
                        <form:option value="0"><spring:message code="approved"/></form:option>
                        <form:option value="1"><spring:message code='common.delete'/></form:option>
                        <form:option value="2"><spring:message code='inapproval'/></form:option>
                        <form:option value="3"><spring:message code="rejected"/></form:option>
                    </form:select>
                </li>
                <li class="btns"><input id="btnSubmit" class="btn btn-primary" type="submit" value="<spring:message code='common.Query'/>"/></li>
                <li class="clearfix"></li>
            </ul>
        </form:form>
    </div>
	<sys:message content="${message}"/>
	<table class="table table-striped table-bordered table-condensed">
		<thead>
		<tr>
			<th style="width:40px;text-align:center;"><input type="checkbox" onclick="cheackAll(this)"/></th>
			<th><spring:message code="template.name"/></th>
			<th><spring:message code='common.resolution'/></th>

			<th><spring:message code="common.applicant"/></th>
           	<th><spring:message code="common.applicant.time"/></th>
			<th>
				<c:if test="${flag}">
					<spring:message code='common.applicant'/>
				</c:if>
				<c:if test="${!flag}">
					<spring:message code='common.approver'/>
				</c:if></th>
			<th><spring:message code="common.approver.time"/></th>
			<th><spring:message code='audit.state'/></th>
			<th><spring:message code='common.remarks'/></th>
		</tr>
		</thead>
		<tbody id="contentTable" >
		<c:forEach items="${page.list}" var="publish">
			<tr>
                    <td style="text-align:center;"><input type="checkbox" id="${publish.id}"/></td>
				<td><a href="${ctx}/templet/eleTemplet/info?publishId=${publish.id}">
					${ publish.templet.name}
				</a></td>
				<td>
					${publish.templet.width} X ${publish.templet.height}
				</td>

				<td>${publish.createBy.name}</td>
				<td>
					<fmt:formatDate value="${publish.createDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
				</td>
				<td> ${flag?publish.createBy.name:publish.checkBy.name}</td>
				<td>
					<fmt:formatDate value="${publish.checkDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
				</td>

				<td>
					<c:if test="${publish.delFlag == '0'}">
						<spring:message code="approved"/>
					</c:if>
					<c:if test="${publish.delFlag == '1'}">
						<spring:message code='common.delete'/>
					</c:if>
					<c:if test="${publish.delFlag == '2'}">
						<spring:message code='inapproval'/>
					</c:if>
					<c:if test="${publish.delFlag == '3'}">
						<spring:message code="rejected"/>
					</c:if>
				</td>
				<td>
						${publish.remarks}
				</td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
</body>
</html>